package com.fsc.fragment;

import com.fsc.fragment.login.Password;
import com.fsc.fragment.login.PasswordDao;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class PwsswordActivity extends Activity implements OnClickListener{
	private EditText et_login;
	private Button btn_login;
	
	private PasswordDao Dao;
	private Password password;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pwssword);
		
		et_login = (EditText) findViewById(R.id.et_login);
		btn_login = (Button) findViewById(R.id.btn_login);
		
		btn_login.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
//
//		
//		int name = Integer.parseInt(et_login.getText().toString());
//		name=123;
//		if(name==123){
//			Intent objIntent = new Intent(this,MainActivity.class);
//			startActivity(objIntent);
//			
//			et_login.setText("");
//			Toast.makeText(this, "登录成功！",Toast.LENGTH_LONG).show();
//			return;
//		}
//		else{
//			Toast.makeText(this, "请输入登录密码",Toast.LENGTH_LONG).show();
//		}
		String name = et_login.getText().toString();
		if(name == null || name.length() <= 0){
			Toast.makeText(this, "用户名不能为空",Toast.LENGTH_LONG).show();
			return;
		}else{
			Dao = new PasswordDao(this);
			if(Dao.getAll(name) >= 1){//存在
				password = Dao.getName(name);
				Intent objIntent = new Intent(this,MainActivity.class);
				startActivity(objIntent);
				Toast.makeText(this, "登录成功！",Toast.LENGTH_LONG).show();
				et_login.setText("");
				return;
			}else{
				Toast.makeText(this, "用户名有误！", Toast.LENGTH_LONG).show();
				return;
			}
		}
	}
}
